package com.xieyong.leetcode;

public class Leetcode2016 {
    public static void main(String[] args) {
        Leetcode2016 leetcode2016 = new Leetcode2016();
        int[] nums = {7,1,5,4};
        int i = leetcode2016.maximumDifference(nums);
        System.out.println(i);
    }


    public int maximumDifference(int[] nums) {
        int len = nums.length,res = -1;
        for(int l = 0,r = 1; r < len;r++) {
            if(nums[r] <= nums[l]) l = r;
            else res = Math.max(res,nums[r] - nums[l]);
        }
        return res;
    }
}
